﻿using System.Collections.Generic;
using CivilRegistry.ControlledModel.Repository;

namespace CivilRegistry.ControlledModel
{
    /// <summary>
    /// The state object.
    /// </summary>
    public partial class State
    {
        #region Local Fields

        /// <summary>
        /// Holds the <see cref="StateRepository"/> instance.
        /// </summary>
        static StateRepository repository = new StateRepository();

        #endregion

        #region Methods

        #region Finder Mehtods

        /// <summary>
        /// Finds the <see cref="State"/> by Id.
        /// </summary>
        /// <param name="id">The id of the <see cref="State"/>.</param>
        /// <returns>Found <see cref="State"/> object, null if not found.</returns>
        public static State FindById(int id)
        {
            return repository.FindBy(state => state.StateId == id);
        }

        /// <summary>
        /// Finds the <see cref="State"/> by name.
        /// </summary>
        /// <param name="name">The name of the <see cref="State"/> to find.</param>
        /// <returns>Found <see cref="State"/> object, null if not found.</returns>
        public static State FindByName(string name)
        {
            return repository.FindBy(state => state.StateName == name);
        }

        /// <summary>
        /// Finds all <see cref="State"/>s.
        /// </summary>
        /// <returns>Found <see cref="State"/> objects, empty if none are found.</returns>
        public static List<State> FindAll()
        {
            List<State> stateList = new List<State>();
            repository.FindAll().ForEach(state => stateList.Add(state));
            return stateList;
        }

        #endregion

        #endregion
    }
}